//------------------------------------------------------------------------------
// @description 管理员端-突出工作-进行中
//------------------------------------------------------------------------------
<script setup  name="OutstandingWorkProceed">
//------------------------------------------------------------------------------
// 模块引入
//------------------------------------------------------------------------------
import { ref } from 'vue';
import { useRouter } from 'vue-router';

import { ElTable,ElTableColumn, ElPagination, ElSelect,ElOption } from 'element-plus';
import { Search } from '@element-plus/icons-vue';
import service from '@/utils/request';

//------------------------------------------------------------------------------
// 数据存储
//------------------------------------------------------------------------------
const router = useRouter();

//表格数据
const tableData = ref([// 表格数据
])
const pageNum = ref(1); // 当前页码
const pageSize = ref(5); // 每页显示的条数
const totalSize = ref(0); // 总条数


// 搜索框相关
const searchValue = ref(''); // 搜索框的值
const searchRef = ref(null);// 右侧搜索框元素


//------------------------------------------------------------------------------
// 数据处理方法
//------------------------------------------------------------------------------

//获取表格数据
const fixedTableData = (data) => {
    if (data.length === 0) return [];
    return data.map(item => {
        return {
            name: item.teacherName,
            teacherId: item.teacherId,
            taskName: item.questionnairename,
            taskId: item.questionnaireId,
            taskState: item.state,
            score: item.sumScore || 0,
            operation: '班级填报详情',
        }
    })
}
const getTableData = (searchValue) => {
    service({
        method: "get",
        url: "/admin/teacherprominentworklist",
        headers: {
            Authorization: localStorage.getItem('token'),
        },
        params: {
            name: searchValue,
            pageNum: pageNum.value,
            pageSize: pageSize.value
        }
    }).then((res) => {
        tableData.value = fixedTableData(res.data.list);
        totalSize.value = res.data.total;
    })
}
getTableData("");


// 搜索框聚焦和失焦事件
const searchFocus = () => {
    searchRef.value.classList.add('searchActive');
};
const searchBlur = () => {
    if (searchValue.value === '') {
        searchRef.value.classList.remove('searchActive');
    }
}
const searchChange = () => {
    getTableData(searchValue.value);
}


//点击班级详情
const operationClick = (row, column) => {
    if (column.property !== 'operation') {
        return;
    }
    router.push({
        path: '/administrator/outstandingWork/proceed/detail',
        query: row
    })
}

//底部分页相关
const handleSizeChange = (val) => {
    pageSize.value = val
    getTableData(searchValue.value);
}
</script>

<template>
        <!-- 进行中内容 -->
        <div class="dataTable">
            <div class="content">
                <!-- 搜索框头部 -->
                <div class="tableHeader">
                    <div class="left">
                        <span>2024-2025学年突出工作情况</span>
                    </div>
                    <div class="right" >
                        <div class="search" ref="searchRef">
                            <input 
                            v-model="searchValue" 
                            type="text" 
                            placeholder="搜索" 
                            @focus="searchFocus" 
                            @blur="searchBlur"
                            @keyup.enter="searchChange"
                            />
                            <el-icon class="icon"><Search /></el-icon>
                        </div>
                    </div>
                </div>
                <!-- 数据表格 -->
                <div class="tableContent">
                    <el-table
                    :data="tableData"
                    :style="{width: '100%'}"
                    height="100%"
                    show-overflow-tooltip
                    empty-text="暂无数据"
                    :header-row-style="{color: '#000'}"
                    @cell-click="operationClick"
                    >
                        <el-table-column align="left" prop="name" label="姓名" width="100"></el-table-column>
                        <el-table-column align="center" prop="teacherId" label="工号" width="150"></el-table-column>
                        <el-table-column align="left" prop="taskName" label="任务名称" width="250"></el-table-column>
                        <el-table-column align="center" prop="taskState" label="任务状态">
                            <template #default="scope">
                                <span :color="scope.row.taskState">{{ scope.row.taskState }}</span>
                            </template>
                        </el-table-column>
                        <el-table-column align="center" prop="score" label="分数"></el-table-column>
                        <el-table-column align="center" prop="operation" label="操作">
                            <template #default="scope">
                                <span style="color:#5a8cff;">{{ scope.row.operation }}</span>
                            </template>
                        </el-table-column>
                    </el-table>
                </div>
                <!-- 底部分页器 -->
                <div class="tableFooter">
                    <div class="left">
                        <div class="total">共计: {{ totalSize}} 条</div>
                    </div>
                    <div class="right">
                        <div class="pagination">
                            <el-pagination
                                layout="prev, pager, next"
                                :total="totalSize"
                                :page-size="pageSize"
                                background
                                size="small"
                                @current-change="handleSizeChange"
                            />                        
                        </div>
                        <div class="selector">
                            <el-select 
                            v-model="pageSize" 
                            placeholder="每页条数" 
                            style="width: 80px;" 
                            size="small"
                            @change="getTableData(searchValue);"
                            >
                                <el-option label="5条/页" :value="5" selected></el-option>
                                <el-option label="10条/页" :value="10"></el-option>
                                <el-option label="20条/页" :value="20"></el-option>
                            </el-select>
                        </div>
                        <div class="jump">
                            <span class="title">前往:</span>
                            <input type="text" v-model="pageNum" @change="getTableData(searchValue);">
                        </div>                        
                    </div>
                </div>
            </div>
        </div>
</template>

<style scoped lang="scss">
    //数据表格
    .dataTable {
        width: 100%;
        height: calc(100% - 7.5vh);
        display: flex;
        justify-content: center;
        align-items: center;
        .content{
            width: 90%;
            height: 90%;
            background-color: #ffffff;
            .tableHeader {
                width: 100%;
                height: 10%;
                display: flex;
                justify-content: space-between;
                font-weight: 600;
                .left {
                    width: 250px;
                    padding-left: 15px;
                    display: flex;
                    align-self: center;
                }
                .right {
                    width: calc(100% - 250px);
                    height: 100%;
                    padding-right: 15px;
                    display: flex;
                    align-items: center;
                    justify-content: flex-end;                  
                    .search {
                        width: 20vw;
                        height: 4vh;
                        display: flex;
                        align-items: center;
                        border-radius: 6px;
                        background-color: #f1f2f3;
                        transition: transform 0.2s ease-in-out; 
                        &:hover{
                            background-color: #e0e1e2;
                        }
                        input{
                            height: 100%;
                            width: 90%;
                            outline: none;
                            border: none;
                            background-color: transparent;
                            text-indent: 1em;
                        }
                        .icon{
                            width: 10%;
                            height: 100%;
                            display: flex;
                            align-items: center;
                            justify-content: center;
                        }
                    }
                }
                .searchActive {
                    transform: translateX(-20vw) scale(1.1);
                    width: 20vw;
                    border: 2px solid #4c5fbc;
                    background-color: #ffffff!important;
                }
            }
            .tableContent {
                width: 100%;
                height: 80%;
                padding: 0 15px;
                font-weight: 500;
                [color="填报中"]{
                    color: #898989;
                }
                [color="审核完成"]{
                    color: #4bc65f;
                }
                [color="未审核"]{
                    color: #ff0000;
                }
            }
            .tableFooter {
                    width: 100%;
                    height: 10%;
                    padding: 0 15px;
                    display: flex;
                    align-items: center;
                    justify-content: space-between;
                    .left{
                        font-size: 12px;
                    }
                    .right{
                        display: flex;
                        gap:15px;
                        .jump{
                            .title{
                                margin-right: 5px;
                                font-size: 12px;
                            }
                            input{
                                width: 25px;
                                height: 25px;
                                text-align: center;
                                line-height: 25px;
                                border: none;
                                outline: none;
                                border-radius: 5px;
                                background-color: #f2f3f5;
                                color:#86909c;
                                &:focus{
                                    border: 1px solid #165dff;
                                }
                            }
                        }
                    }
            }
        }
    }
</style>